<template>
	<view class="content">
		<view class="header_swiper">
			<swiper style="height: 280px;" :indicator-dots="false" :autoplay="true" :interval="3000" :circular="true"
				:duration="1000">
				<swiper-item v-for="(item,index) in imagesList" :key="index">
					<view class="swiper-item">
						<image :src="'http://localhost:8080/api/img/'+item" mode=""></image>
					</view>
				</swiper-item>
			</swiper>
		</view>
		<view class="briefly_uInfo">
			<uni-card :isShadow="true">
				<view class="content">
					<view class="avatar">
						<image src="../../static/imgs/Papers.co-bl94-art-girl-cute-face-anime-pretty-android-large.jpg"
							mode=""></image>
					</view>
					<view class="info">
						<view class="uName">
							<text v-if="phone">{{phone}}</text>
							<text v-else>尊敬的用户</text>
						</view>
						<view class="ad">
							<text>会员可享【闲时优惠】等多项权益</text>
						</view>
					</view>
					<view class="login">
						<button type="warn" v-if="!phone" open-type="getPhoneNumber" size="mini"
							@getphonenumber="getPhoneNumberInfo" @click="inputDialogToggle">授权登录</button>
					</view>
				</view>
			</uni-card>
		</view>
		<view class="takeaway-himself">
			<view class="content">
				<view class="himself" @click="toBuy()">
					<!-- <view class="himself_content">
						<view class="text">
							<text class="title">自取</text>
							<text class="description">下单免排队</text>
						</view>
					</view> -->
					<image style="width: 100%;height: 100%; border-radius: 10px;" src="../../static/imgs/himself.png"
						mode=""></image>
				</view>
				<view class="takeaway" @click="toBuy()">
					<!-- <view class="takeaway_content">
						<view class="text">
							<text class="title">外卖</text>
							<text class="description">甜蜜送到家</text>
						</view>
					</view> -->
					<image style="width: 100%;height: 100%;border-radius: 10px;" src="../../static/imgs/waimai.png"
						mode=""></image>
				</view>
			</view>
		</view>
		<view class="articleRecommendation" @click="toArticle()">
			<view class="content">
				<view class="left">
					<text>今日推荐</text>
				</view>
			</view>
		</view>
		<uni-popup ref="inputDialog" type="dialog">
			<uni-popup-dialog ref="inputClose" before-close="true" mode="input" title="输入手机号" value=""
				placeholder="请输入内容" @close="closeDialog" @confirm="dialogInputConfirm"></uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				title: '首页',
				imagesList: [],
				phone: ""
			}
		},
		onLoad() {
			this.getCarousel()
			this.getPhone()
		},
		methods: {
			//查看文章推荐
			toArticle() {
				uni.navigateTo({
					url: "/packges/home/article/article"
				})
			},
			// 获取轮播图
			async getCarousel() {
				let res = await uni.$http.good.reqGetCarousel()
				this.imagesList = res.data.images
				this.formateImg()
			},

			//手机号确认框
			async dialogInputConfirm(e) {
				if (e.length !== 11) {
					return uni.showToast({
						title: "手机号格式错误",
						icon: 'error',
						duration: 1000
					})
				}
				let usrInfo = uni.getStorageSync("userInfo")
				let params = {
					openid: usrInfo.openid,
					phone: e
				}
				let res = await uni.$http.user.openidBindPhone(params);
				if (res.code == "200") {
					uni.showToast({
						title: "绑定成功",
						icon: 'error',
						duration: 1000
					})
					this.phone = e
					getApp().globalData.phone = e
					this.$refs.inputDialog.close()
				}
			},

			inputDialogToggle() {
				this.$refs.inputDialog.open()
			},

			closeDialog() {
				this.$refs.inputDialog.close()
			},

			//查看手机绑定状态
			async getPhone() {
				let params = {
					openid: uni.getStorageSync("userInfo").openid
				}
				let res = await uni.$http.user.reqGetPhoneStatus(params)
				if (res.code == "200") {
					if (res.data != null && res.data != "") {
						this.phone = res.data
						getApp().globalData.phone = res.data
					}
				}
			},

			//获取手机号
			getPhoneNumberInfo(e) {
				console.log(e);
			},

			toBuy() {
				uni.switchTab({
					url: "/pages/orderFood/orderFood"
				})
			},

			//格式化图片
			formateImg() {
				this.imagesList = this.imagesList.replace(/\[|\]/g, "").replace(/\s+/g, "").split(",");
			}
		}
	}
</script>

<style lang="less" scoped>
	.header_swiper {
		image {
			width: 100%;
			height: 280px;
			border-radius: 8px;
		}
	}

	.briefly_uInfo {
		position: relative;
		top: -30px;


		.uni-card {
			border-radius: 10px;
		}

		.content {
			display: flex;
			justify-content: space-between;
			align-items: center;

			.avatar {

				image {
					width: 46px;
					height: 46px;
					border-radius: 50%;
				}
			}

			.info {
				display: flex;
				flex-direction: column;
				padding-right: 8px;
				margin-left: -8px;

				.uName {
					font-weight: 700;
					color: black;
				}

				.ad {
					font-size: 10px;
					color: #b1b1b1;

					text {
						line-height: 5px;
					}
				}

			}

			.login {
				width: 100px;
				margin-right: -15px;
			}
		}


	}

	.takeaway-himself {
		margin-top: -30px;

		.content {
			display: flex;
			justify-content: space-around;
			padding: 0 4px;

			.himself,
			.takeaway {
				width: 175px;
				height: 175px;
				border-radius: 10px;
				background-color: antiquewhite;
			}

			.text {
				display: flex;
				flex-direction: column;
				justify-content: center;
				margin-top: 20px;
				margin-left: 15px;

				.title {
					font-size: 18px;
					font-weight: 700;
					margin-bottom: 7px;
				}

				.description {
					font-size: 12px;
					color: #969595;
				}
			}
		}
	}

	.articleRecommendation {
		.content {
			display: flex;
			justify-content: space-around;
		}

		.content>view {
			width: 95%;
			height: 80px;
			border-radius: 8px;
			margin: 10px 0;
			text-align: center;
			line-height: 80px;
			font-size: 18px;
			font-weight: 700;
			background-color: aquamarine;
		}

	}
</style>
